<?php
/**
*
* clase TEdit campo de texto
* elaborada por: Ebrain cedeno
*
**/

class TEdit{
    
    public $Name;
    public $Width = '';
    public $Height = '';
    public $Top = '';
    public $Left = '';
    public $Visible = true;
    public $ReadOnly;
    public $MaxLength = 0;
    public $Font;
    public $FontColor;
    public $NumbersOnly;
    public $Text;
    public $SelLength;
    public $BorderStyle;
    public $Color;
    public $Cursor;
    public $Password = false;
    public $Enabled = true;
    public $Aditional = array();
    
    public function OnChanged($function_name,$TEditObject,$param=array()){
        call_user_func($TEditObject->$function_name,$param);
    }
    
    public function show(){
        
        //cargando el tipo de campo
        if ($this->Password == true){
            $method = "password";
        }
        elseif ($this->Password == false){
            $method = "text";
        }
        else{
            die("no se encontro el tipo de control solicitado");
        }
        
        $readOnly = ($this->ReadOnly == true)?'readOnly="'.$this->ReadOnly.'"':"";
        $maxLength = ($this->MaxLength > 0)?'maxlength="'.(string)$this->MaxLength.'"':'';
        
        // cargando los parametros de style
        
        $this->Color = ($this->Color != "")?"background-color:".$this->Color.";":$this->Color;
        $this->BorderStyle = ($this->BorderStyle != "")?"border:".$this->BorderStyle.";":$this->BorderStyle;
        $this->Font = ($this->Font != "")?"font:".$this->Font.";":$this->Font;
        $this->FontColor = ($this->FontColor != "")?"color:".$this->FontColor.";":$this->FontColor;
        $visible = ($this->Visible == false)?"display:none; visibility:hidden;":"";
        $width = ($this->Width != '')?'width:'.$this->Width.";":'';
        $height = ($this->Height != '')?'height:'.$this->Height.";":'';
        $top = ($this->Top != '')?"position:absolute; top:".$this->Top.";":'';
        $left = ($this->Left != '')?"position:absolute; left:".$this->Left.";":'';
        $cursor = ($this->Cursor != '')?'cursor:'.$this->Cursor.";":'';
        $enabled = ($this->Enabled == false)?'disabled="true"':'';
        
        //cargando los parametros adicionales
        
        $Aditional = '';
        $css_aditional = '';
        
        if (!is_array($this->Aditional)){
            die("Se esperaba un array de parametros adicionales");
        }
        else{
            if (count($this->Aditional) > 0){
                foreach ($this->Aditional as $llave=>$value){
                    if (strtolower($llave) != "style" ){
                        $Aditional .= $llave.'="'.$value.'" ';
                    }
                    else{
                        $css_aditional .= implode(';', $value).";";
                    }
                }
            }
        }
        
        $input = '<input name = "'.$this->Name.'" id = "'.$this->Name.'" '.$Aditional.' type="'.$method.'" value="'.$this->Text.'" style="'.$width.$height.$this->Color.$this->BorderStyle.$this->Font.$this->FontColor.$visible.$top.$left.$cursor.$css_aditional.'" '.$maxLength.' '.$readOnly.' '.$enabled.' />';
        return $input;
    }
    
}

?>
